<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">用户协议</ui:define>
    <ui:define name="content">
        <h:form>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"
                                         rendered="#{security:areAllGranted('LOAN_USER_AGREEMENT_SEARCH')}"/>
                        <p:columnToggler datasource="loanUserAgreementDataTable" trigger="toggler"
                                         rendered="#{security:areAllGranted('LOAN_USER_AGREEMENT_SEARCH')}"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"
                                         rendered="#{loanUserAgreementListBean.isNormal() and security:areAllGranted('LOAN_USER_AGREEMENT_SEARCH')}"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         rendered="#{loanUserAgreementListBean.isNormal() and security:areAllGranted('LOAN_USER_AGREEMENT_EXPORT')}"
                                         ajax="false">
                            <p:dataExporter type="xls" target="loanUserAgreementDataTable" fileName="export"/>
                        </p:commandButton>
                        <p:commandButton icon="fa fa-plus" value="新增"
                                         action="#{loanUserAgreementListBean.onAdd}"
                                         rendered="#{loanProductListBean.isNormal() and security:areAllGranted('LOAN_USER_AGREEMENT_ADD')}">
                            <f:setPropertyActionListener value="/views/family/user/loan-user-agreement-list.xhtml"
                                                         target="#{currentUserBean.back}"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="8" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-2"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">

                                <p:outputLabel for="startDate" value="开始日期"/>
                                <p:calendar id="startDate" value="#{loanUserAgreementListBean.$.startDate}"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"/>

                                <p:outputLabel for="endDate" value="结束日期"/>
                                <p:calendar id="endDate" value="#{loanUserAgreementListBean.$.endDate}"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"/>

                                <p:outputLabel for="parentProductId" value="所属大产品"/>
                                <p:selectManyMenu id="parentProductId" value="#{loanUserAgreementListBean.$.parentProductId}"
                                                  filter="true"
                                                  filterMatchMode="contains" showCheckbox="true">
                                    <f:selectItems value="#{loanUserAgreementListBean.dictionaries[DictionaryCode.LARGE_COMMON_PRODUCT]}"
                                                   var="dic"
                                                   itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectManyMenu>

                                <p:outputLabel for="status" value="状态"/>
                                <p:selectOneMenu id="status" value="#{loanUserAgreementListBean.$.status}">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItem itemLabel="上线" itemValue="1" noSelectionOption="true"/>
                                    <f:selectItem itemLabel="下线" itemValue="0" noSelectionOption="true"/>
                                </p:selectOneMenu>

                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="loanUserAgreementDataTable"
                                         style="width: 100%"
                                         var="record"
                                         value="#{loanUserAgreementListBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{loanUserAgreementListBean.selectedRecords}"
                                         resizableColumns="true"
                                         rendered="#{security:areAllGranted('LOAN_USER_AGREEMENT_SEARCH')}">

                                <p:column headerText="操作" rendered="#{loanUserAgreementListBean.isNotBatch()}">
                                    <p:splitButton icon="fa fa-eye"
                                                   action="#{loanUserAgreementListBean.onEdit(record.id)}"
                                                   process="@this">
                                        <f:setPropertyActionListener
                                                value="/views/family/user/loan-user-agreement-list.xhtml"
                                                target="#{currentUserBean.back}"/>
                                        <p:menuitem value="上线" icon="fa fa-arrow-up"
                                                    action="#{loanUserAgreementListBean.onOnline(record.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{record.status == 0}"/>
                                        <p:menuitem value="下线" icon="fa fa-arrow-down"
                                                    actionListener="#{loanUserAgreementListBean.onOffline(record.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{record.status == 1}"/>
                                        <p:menuitem value="删除" icon="fa fa-fw fa-remove"
                                                    actionListener="#{loanUserAgreementListBean.onDelete(record.id)}"
                                                    process="@this" update="@form">
                                            <p:confirm header="提示信息" message="是否确定删除?" icon="ui-icon-alert"/>
                                        </p:menuitem>
                                    </p:splitButton>
                                </p:column>

                                <p:column headerText="状态">
                                    <h:outputText value="#{loanUserAgreementListBean.translate(DictionaryCode.LOAN_USER_AGREEMENT_STATUS, record.status)}"/>
                                </p:column>

                                <p:column headerText="协议ID">
                                    <h:outputText value="#{record.ruleId}"/>
                                </p:column>

                                <p:column headerText="更新时间">
                                    <h:outputText value="#{record.createDate}">
                                        <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>

                                <p:column headerText="作用大产品">
                                    <h:outputText value="#{loanUserAgreementListBean.translate(DictionaryCode.LARGE_COMMON_PRODUCT, record.parentProductId)}"/>
                                </p:column>

                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
